package com.stylefeng.guns.rest.modular.wz.api.v1;


import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.rest.common.base.controller.ApiBaseController;
import com.stylefeng.guns.rest.common.constant.Consts;
import com.stylefeng.guns.rest.common.constant.WzConsts;
import com.stylefeng.guns.rest.common.persistence.dao.*;
import com.stylefeng.guns.rest.common.persistence.model.*;
import com.stylefeng.guns.rest.common.util.AliyunSmsUtil;
import com.stylefeng.guns.rest.common.util.StringUtils;
import com.stylefeng.guns.rest.common.util.WeinXinUtil;
import com.stylefeng.guns.rest.domain.ParamMap;
import com.stylefeng.guns.rest.domain.Res;
import com.stylefeng.guns.rest.enums.EnPfFile;
import com.stylefeng.guns.rest.enums.EnWzUser;
import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil;
import com.stylefeng.guns.rest.modular.wz.cache.CacheService;
import com.stylefeng.guns.rest.modular.wz.controller.TextScanService;
import com.stylefeng.guns.rest.modular.wz.service.impl.WzUserInfoServiceImpl;
import com.stylefeng.guns.rest.modular.wz.service.impl.WzUserServiceImpl;
import com.stylefeng.guns.rest.pay.ali.AlipayConfig;
import com.stylefeng.guns.rest.pay.method.PayMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 用户活动信息表
 *
 * @author ruiyifeng123
 * @since 2018-03-26
 */
@RestController
@RequestMapping("/wz/api/v1/wzUserInfo/")
public class WzUserInfoApi extends ApiBaseController{

    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private WzUserMapper userMapper;
    @Autowired
    private WzUserInfoServiceImpl userInfoService;
    @Autowired
    private WzUserFixedInfoMapper userFixedInfoMapper;
    @Autowired
    private WzUserOauthMapper userOauthMapper;
    @Autowired
    private WzUserRecommendMapper userRecommendMapper;
    @Autowired
    private WzConsts wzConsts;
    @Autowired
    private PfFileMapper pfFileMapper;
    @Autowired
    private CacheService cacheService;
    @Autowired
    private WzUserServiceImpl userService;
    @Autowired
    private TextScanService textScanService;
    @Autowired
    private WzUserOauthMapper wzUserOauthMapper;

    /**
     * 我的邀请码
     */
//    @Transactional
//    @PostMapping("invitation.index")
//    public Res invitationCode(@RequestBody ParamMap paramMap){
//        int pageNum = paramMap.getIntMisValid("pageNum");
//        int pageSize = paramMap.getIntMisValid("pageSize");
//        Long userCode = jwtTokenUtil.getUserCodeFromToken();
//        String sql = "nick_name As nickName,avatar_url As avatarUrl,invitation_reward As invitationReward,create_time As createTime";
//        List<Map<String,Object>> userRecommends = userRecommendMapper.selectMapsPage(new Page<>(pageNum,pageSize),new EntityWrapper<WzUserRecommend>().setSqlSelect(sql).eq("accept_user_code",userCode).orderBy("create_time",false));
//        return Res.success(paramMap.data(userRecommends));
//    }


    /**
     * 实名认证 merchant
     */
    @Transactional
    @PostMapping("authentication.realName")
    public Res realNameAuthentication(@RequestBody ParamMap paramMap) throws Exception{
        String   realName = paramMap.getStrMisValid("realName");
        String   idCard = paramMap.getStrMisValid("idCard");
        String   idCardFrontUrl = paramMap.getStrMisValid("idCardFrontUrl");
        String   idCardBackUrl = paramMap.getStrMisValid("idCardBackUrl");
        int   gender = paramMap.getIntMisValid("gender");
        String   birthday = paramMap.getStrMisValid("birthday");
        String   idCardAddress = paramMap.getStrValid("idCardAddress");
        String   nationality = paramMap.getStrValid("nationality");
        int count = userFixedInfoMapper.selectCount(new EntityWrapper<WzUserFixedInfo>().eq("id_card",idCard).ge("status",EnWzUser.STATUS_RealName_SUCCESS.getIndex()));
        if(count > 0){
            return Res.fail("此身份证已经被使用!");
        }
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUser> userList = userMapper.selectList(new EntityWrapper<WzUser>().eq("user_code",userCode));
        if(userList.get(0).getStatus() == 0){
            return Res.fail("账户冻结中!");
        }
        //用户数据修改
        userList.get(0).setStatus(EnWzUser.STATUS_RealName_WaitCheck.getIndex());
        //用户信息修改
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        userFixedInfos.get(0).setIdCard(idCard);
        userFixedInfos.get(0).setBirthday(birthday);
        userFixedInfos.get(0).setGender(gender);
        userFixedInfos.get(0).setRealName(realName);
        userFixedInfos.get(0).setIdCardFrontUrl(idCardFrontUrl);
        userFixedInfos.get(0).setIdCardBackUrl(idCardBackUrl);
        userFixedInfos.get(0).setIdCard(idCard);
        userFixedInfos.get(0).setIdCardAddress(idCardAddress);
        userFixedInfos.get(0).setNationality(nationality);
        userFixedInfos.get(0).setStatus(EnWzUser.STATUS_RealName_WaitCheck.getIndex());
        int r = userMapper.updateById(userList.get(0));
        if(r > 0){
            r = userFixedInfoMapper.updateById(userFixedInfos.get(0));
            if(r > 0){
                List<PfFile> files1 = pfFileMapper.selectList(new EntityWrapper<PfFile>().eq("file_url",idCardFrontUrl));
                if(files1.size() > 0){
                    files1.get(0).setStatus(EnPfFile.File_Status_Used.getIndex());
                    pfFileMapper.updateById(files1.get(0));
                }
                List<PfFile> files2 = pfFileMapper.selectList(new EntityWrapper<PfFile>().eq("file_url",idCardBackUrl));
                if(files2.size() > 0){
                    files2.get(0).setStatus(EnPfFile.File_Status_Used.getIndex());
                    pfFileMapper.updateById(files2.get(0));
                }
                if (Consts.dev.equals("false")) {
                    for (String c : Consts.AuditorTel) {
                        SendSmsResponse response = AliyunSmsUtil.sendAdminSms(c, "有新的实名认证需要审核", Consts.ADMIN_TEMPLATE_CODE);
                    }
                }
                return Res.success();
            }
        }
        return Res.fail();
    }

    /**
     * 实名认证成功数据
     */
    @PostMapping("authentication.data")
    public Res authenticationData(@RequestBody ParamMap paramMap){
        int type = paramMap.getIntMisValid("type");
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUser> userList = userMapper.selectList(new EntityWrapper<WzUser>().eq("user_code",userCode));
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        paramMap.put("idCard","");//身份证号码
        paramMap.put("realName","");//真实姓名
        paramMap.put("gender",0);//性别
        paramMap.put("birthday","");//出生日期
        paramMap.put("merchantName","");//公司名称
        paramMap.put("merchantRegNum","");//公司注册号
        if(type == 1){
            if(userList.get(0).getRole() == EnWzUser.ROLE_RealName.getIndex() || userList.get(0).getRole() == EnWzUser.ROLE_MERCHANT.getIndex() || userList.get(0).getRole() == EnWzUser.ROLE_SUPER_ADMIN.getIndex()){
                paramMap.put("idCard",userFixedInfos.get(0).getIdCard());
                paramMap.put("realName",userFixedInfos.get(0).getRealName());
                paramMap.put("gender",userFixedInfos.get(0).getGender());
                paramMap.put("birthday",userFixedInfos.get(0).getBirthday());
                return Res.success(paramMap);
            }else{
                return Res.fail("请先实名认证!");
            }
        }else if(type == 2){
            if(userList.get(0).getRole() == EnWzUser.ROLE_MERCHANT.getIndex() || userList.get(0).getRole() == EnWzUser.ROLE_SUPER_ADMIN.getIndex()){
                paramMap.put("merchantName",userFixedInfos.get(0).getMerchantName());
                paramMap.put("merchantRegNum",userFixedInfos.get(0).getMerchantRegNum());
                return Res.success(paramMap);
            }else{
                return Res.fail("请先认证商户!");
            }
        }
        return Res.fail();
    }


    /**
     * 商户认证
     */
    @Transactional
    @PostMapping("authentication.merchant")
    public Res merchantAuthentication(@RequestBody ParamMap paramMap){
        String   merchantName = paramMap.getStrValid("merchantName");
        String   merchantLicenseUrl = paramMap.getStrMisValid("merchantLicenseUrl");
        String   merchantPerson = paramMap.getStrValid("merchantPerson");
        String   merchantAddress = paramMap.getStrValid("merchantAddress");
        String   merchantCaptial = paramMap.getStrValid("merchantCaptial");
        String   merchantRegNum = paramMap.getStrMisValid("merchantRegNum");
        String   merchantEstablishDate = paramMap.getStrValid("merchantEstablishDate");
        String   merchantValidPeriod = paramMap.getStrValid("merchantValidPeriod");
        String   merchantBusiness = paramMap.getStrValid("merchantBusiness");
        int count = userFixedInfoMapper.selectCount(new EntityWrapper<WzUserFixedInfo>().eq("merchant_reg_num",merchantRegNum).eq("status",EnWzUser.STATUS_MERCHANT_SUCCESS.getIndex()));
        if(count > 0){
            return Res.fail("此营业执照已经被使用!");
        }
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        WzUser user = cacheService.user(userCode);
        if(user.getStatus() == 0){
            return Res.fail("账户资金异常，冻结中!");
        }
        int type = 0;
        if(user.getRole() == EnWzUser.ROLE_USER.getIndex()){
            String   realName = paramMap.getStrMisValid("realName");
            String   idCard = paramMap.getStrMisValid("idCard");
            String   idCardFrontUrl = paramMap.getStrMisValid("idCardFrontUrl");
            String   idCardBackUrl = paramMap.getStrMisValid("idCardBackUrl");
            int   gender = paramMap.getIntMisValid("gender");
            String   birthday = paramMap.getStrMisValid("birthday");
            String   idCardAddress = paramMap.getStrMisValid("idCardAddress");
            String   nationality = paramMap.getStrMisValid("nationality");
            int c = userFixedInfoMapper.selectCount(new EntityWrapper<WzUserFixedInfo>().eq("id_card",idCard).ge("status",EnWzUser.STATUS_RealName_SUCCESS.getIndex()));
            if(c > 0){
                return Res.fail("此身份证已经被使用!");
            }
            type = 1;
        }else if(user.getRole() == EnWzUser.ROLE_RealName.getIndex()){
            type = 2;
        }
        //用户数据修改
        user.setStatus(EnWzUser.STATUS_MERCHANT_WaitCheck.getIndex());
        //用户数据保存
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        if(type == 1){
            userFixedInfos.get(0).setIdCard(paramMap.getStr("idCard"));
            userFixedInfos.get(0).setRealName(paramMap.getStr("realName"));
            userFixedInfos.get(0).setIdCardFrontUrl(paramMap.getStr("idCardFrontUrl"));
            userFixedInfos.get(0).setIdCardBackUrl(paramMap.getStr("idCardBackUrl"));
            userFixedInfos.get(0).setIdCardAddress(paramMap.getStr("idCardAddress"));
            userFixedInfos.get(0).setBirthday(paramMap.getStr("birthday"));
            userFixedInfos.get(0).setGender(paramMap.getInt("gender"));
            userFixedInfos.get(0).setNationality(paramMap.getStr("nationality"));
            userFixedInfos.get(0).setMerchantName(paramMap.getStr("merchantName"));
            userFixedInfos.get(0).setMerchantLicenseUrl(paramMap.getStr("merchantLicenseUrl"));
            userFixedInfos.get(0).setMerchantPerson(paramMap.getStr("merchantPerson"));
            userFixedInfos.get(0).setMerchantAddress(paramMap.getStr("merchantAddress"));
            userFixedInfos.get(0).setMerchantCaptial(paramMap.getStr("merchantCaptial"));
            userFixedInfos.get(0).setMerchantRegNum(paramMap.getStr("merchantRegNum"));
            userFixedInfos.get(0).setMerchantEstablishDate(paramMap.getStr("merchantEstablishDate"));
            userFixedInfos.get(0).setMerchantValidPeriod(paramMap.getStr("merchantValidPeriod"));
            userFixedInfos.get(0).setMerchantBusiness(paramMap.getStr("merchantBusiness"));
            userFixedInfos.get(0).setStatus(EnWzUser.STATUS_MERCHANT_WaitCheck.getIndex());
        }else if(type == 2){
            userFixedInfos.get(0).setMerchantName(paramMap.getStr("merchantName"));
            userFixedInfos.get(0).setMerchantLicenseUrl(paramMap.getStr("merchantLicenseUrl"));
            userFixedInfos.get(0).setMerchantPerson(paramMap.getStr("merchantPerson"));
            userFixedInfos.get(0).setMerchantAddress(paramMap.getStr("merchantAddress"));
            userFixedInfos.get(0).setMerchantCaptial(paramMap.getStr("merchantCaptial"));
            userFixedInfos.get(0).setMerchantRegNum(paramMap.getStr("merchantRegNum"));
            userFixedInfos.get(0).setMerchantEstablishDate(paramMap.getStr("merchantEstablishDate"));
            userFixedInfos.get(0).setMerchantValidPeriod(paramMap.getStr("merchantValidPeriod"));
            userFixedInfos.get(0).setMerchantBusiness(paramMap.getStr("merchantBusiness"));
            userFixedInfos.get(0).setStatus(EnWzUser.STATUS_MERCHANT_WaitCheck.getIndex());
        }
        boolean r = userService.saveUserFixedInfo(user,userFixedInfos.get(0),type);
        if(r){
            return Res.success();
        }
        return Res.fail();
    }

    /**
     * 修改个人信息
     */
    @Transactional
    @PostMapping("update.userInfo")
    public Res updateInfo(@RequestBody ParamMap paramMap) throws Exception{
        String  nickName = paramMap.getStrValid("nickName");
        String  avatarUrl = paramMap.getStrValid("avatarUrl");
//        boolean rr = textScanService.textScan(nickName);
//        if(!rr){
//            return Res.fail("请文明用语!");
//        }
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUser> userList = userMapper.selectList(new EntityWrapper<WzUser>().eq("user_code",userCode));
        userList.get(0).setAvatarUrl(avatarUrl);
        userList.get(0).setNickName(nickName);
        int r = userMapper.updateById(userList.get(0));
        if(r > 0){
            List<PfFile> files = pfFileMapper.selectList(new EntityWrapper<PfFile>().eq("file_url",avatarUrl));
            if(files.size() > 0){
                files.get(0).setStatus(2);
                r = pfFileMapper.updateById(files.get(0));
                if(r > 0){
                    return Res.success();
                }
            }
            return Res.success();
        }
        return Res.fail();
    }

    /**
     * 修改密码
     */
    @PostMapping("update.psw")
    public Res updatePsw(@RequestBody ParamMap paramMap){
        String password = paramMap.getStrMisValid("password");
        String vaildCode = paramMap.getStrMisValid("vaildCode");
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        //业务处理
        Res res = userInfoService.updatePsw(paramMap,userCode);
        return res;
    }

    /**
     * 我的支付宝绑定参数
     */
    @PostMapping("alipay.token")
    public Res alipayToken() throws Exception{
        String infoStr = PayMethod.alipayOauthToken("","AUTHACCOUNT");
        return Res.success(infoStr);
    }

    /**
     * 已绑定账号
     */
    @PostMapping("userOauth.bind")
    public Res userBind() throws Exception{
        ParamMap paramMap = new ParamMap();
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        paramMap.put("alipay",0);
        paramMap.put("weixin",0);
        if(!StringUtils.isBlankStr(userFixedInfos.get(0).getAlipayUserId())){
            paramMap.put("alipay",1);
        }
        if(!StringUtils.isBlankStr(userFixedInfos.get(0).getWeixinOpenid())){
            paramMap.put("weixin",1);
        }
        return Res.success(paramMap);
    }


    /**
     * 解绑账号
     */
    @Transactional
    @PostMapping("userOauth.unbind")
    public Res userUnbind(@RequestBody ParamMap paramMap) throws Exception{
        String  type = paramMap.getStrMisValid("type");
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        List<WzUserOauth> userOauths = null;
        if(type.equals("alipay")){
            if(1 == 1){
                return Res.fail("暂时不支持解绑支付宝!");
            }
            int r = userOauthMapper.delete(new EntityWrapper<WzUserOauth>().eq("alipay_user_id",userFixedInfos.get(0).getAlipayUserId()));
            userFixedInfos.get(0).setAlipayUserId("");
            if(r > 0){
                r = userFixedInfoMapper.updateById(userFixedInfos.get(0));
                if(r > 0){
                    return Res.success();
                }
            }
            return Res.fail();
        }
        if(type.equals("weixin")){
            if(1 == 1){
                return Res.fail("暂时不支持解绑微信!");
            }
            int r = userOauthMapper.delete(new EntityWrapper<WzUserOauth>().eq("openid",userFixedInfos.get(0).getWeixinOpenid()));
            userFixedInfos.get(0).setWeixinOpenid("");
            if(r > 0){
                r = userFixedInfoMapper.updateById(userFixedInfos.get(0));
                if(r > 0){
                    return Res.success();
                }
            }
            return Res.fail();
        }
        return Res.fail();
    }

    /**
     * 绑定新手机号
     */
    @PostMapping("bind.account")
    public Res bindAccount(@RequestBody ParamMap paramMap){
        int type = paramMap.getIntMisValid("type");
        String vaildCode = paramMap.getStrMisValid("vaildCode");
        if(type == 1){
            String oldAccount = paramMap.getStrMisValid("oldAccount");
        }else if(type == 2){
            String newAccount = paramMap.getStrMisValid("newAccount");
        }
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        //业务处理
        Res res = userInfoService.bindAccount(paramMap,userCode);
        return res;
    }

    /**
     * 绑定微信帐号
     */
    @Transactional
    @PostMapping("bind.weixin")
    public Res bindWeixin(@RequestBody ParamMap paramMap){
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        //参数校验
        String openid = paramMap.getStrMisValid("openid");//openid
        List<WzUserFixedInfo> oauthList = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("weixin_openid",openid));
        if(oauthList.size() > 0){
            return Res.fail("微信不可重复绑定!");
        }
        String nickName = paramMap.getStrMisValid("nickName");
        nickName = WeinXinUtil.emojiFilter(nickName);
        paramMap.set("nickName",nickName);
        String gender = paramMap.getStrMisValid("gender");
        String avatarUrl = paramMap.getStrMisValid("avatarUrl");
        String unionid = paramMap.getStrMisValid("unionid");
        List<WzUserFixedInfo> userFixedInfos = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("user_code",userCode));
        userFixedInfos.get(0).setWeixinOpenid(openid);
        userFixedInfoMapper.updateById(userFixedInfos.get(0));
        List<WzUserOauth> userOauths = userOauthMapper.selectList(new EntityWrapper<WzUserOauth>().eq("openid ",openid));
        if(userOauths.size() > 0){//更新用户三方登陆
            userOauths.get(0).setNickName(paramMap.getStr("nickName"));
            userOauths.get(0).setAvatarUrl(paramMap.getStr("avatarUrl"));
            userOauths.get(0).setGender(Integer.parseInt(paramMap.getStr("gender")));
            userOauths.get(0).setPaltform(EnWzUser.OAUTH_PALTFORM_weixin.getIndex());
            userOauths.get(0).setOpenid(paramMap.getStr("openid"));
            userOauthMapper.updateById(userOauths.get(0));
        }else{//新建三方用户
            WzUserOauth wzUserOauth = new WzUserOauth();
            wzUserOauth.setCreateTime(new Date());
            wzUserOauth.setNickName(paramMap.getStr("nickName"));
            wzUserOauth.setAvatarUrl(paramMap.getStr("avatarUrl"));
            wzUserOauth.setGender(Integer.parseInt(paramMap.getStr("gender")));
            wzUserOauth.setUserCode(userCode);
            wzUserOauth.setOpenid(paramMap.getStr("openid"));
            wzUserOauth.setUnionid(paramMap.getStr("unionid"));
            wzUserOauth.setPaltform(EnWzUser.OAUTH_PALTFORM_weixin.getIndex());
            userOauthMapper.insert(wzUserOauth);//新建用户三方登陆
        }
        return Res.success();
    }

    /**
     * 绑定支付宝账号
     */
    @PostMapping("bind.alipay")
    public Res alipayOauth(@RequestBody ParamMap paramMap) throws Exception{
        String  userId = paramMap.getStrMisValid("userId");
        String  authCode = paramMap.getStrMisValid("authCode");
        Long userCode = jwtTokenUtil.getUserCodeFromToken();
        List<WzUserFixedInfo> oauthList = userFixedInfoMapper.selectList(new EntityWrapper<WzUserFixedInfo>().eq("alipay_user_id",userId));
        if(oauthList.size() > 0){
            return Res.fail("支付宝不可重复绑定!");
        }
        //获取accessToken
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",AlipayConfig.app_id,AlipayConfig.private_key,"json","GBK",AlipayConfig.alipay_public_key,"RSA2");
        AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
        request.setGrantType("authorization_code");
        request.setCode(authCode);
        request.setRefreshToken("");
        AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            return Res.fail("调用失败");
        }
        //获取支付宝用户信息
        AlipayUserInfoShareRequest userInfoRequest = new AlipayUserInfoShareRequest();
        AlipayUserInfoShareResponse userInfoResponse = alipayClient.execute(userInfoRequest,response.getAccessToken());
        if(userInfoResponse.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            return Res.fail("调用失败");
        }
        paramMap.put("nickName",userInfoResponse.getNickName());
        if(userInfoResponse.getGender().equals("m")){
            paramMap.put("gender",1);
        }else if(userInfoResponse.getGender().equals("f")){
            paramMap.put("gender",0);
        }
        paramMap.put("avatarUrl",userInfoResponse.getAvatar());
        boolean r = userInfoService.saveAlipayOauth(userCode,paramMap);
        if(r){
            return Res.success();
        }
        return Res.fail();
    }

}

